{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b7154949",
   "metadata": {},
   "source": [
    "---------\n",
    "* 时间： 2022/10/18\n",
    "* 记录人： 薛欣怡\n",
    "-------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1d47e62b",
   "metadata": {},
   "source": [
    "# 本周知识点"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f860071a",
   "metadata": {},
   "source": [
    "> 1.while循环    \n",
    "> 2.购物车的练习      \n",
    "> 3.元组_集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb6faed9",
   "metadata": {},
   "outputs": [],
   "source": [
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯。。。\") # 这个就无限循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b3a5aef",
   "metadata": {},
   "outputs": [],
   "source": [
    "# while True 可以实现for+range的方法\n",
    "# while true 一般用于不确定的循环次数和无限次循环操作。\n",
    "count = 0\n",
    "while True:\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯。。。\",count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8c528989",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card56\n"
     ]
    }
   ],
   "source": [
    "# 猜数字小游戏 ：0<n<100 ,5次机会猜数字，每次猜完出题人提示，你猜的数有点大/有点小\n",
    "\n",
    "hide_card = int(input(\"hide_card\")) #出题人\n",
    "count = 0 #意思是从0开始"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d474f4a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hide_card:········\n",
      "游戏开始啦\n",
      "guess_digit:65\n",
      "往大了猜。。。\n",
      "guess_digit:90\n",
      "往大了猜。。。\n",
      "guess_digit:98\n",
      "往小了想想。。\n",
      "guess_digit:97\n",
      "往小了想想。。\n",
      "guess_digit:93\n",
      "往大了猜。。。\n",
      "猜这么多次都不对，你个笨蛋！\n",
      "正确答案是： 95\n"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0\n",
    "# 以上是把时输入的数字隐藏\n",
    "# print（hide_card）\n",
    "if hide_card <100 and hide_card>0 :\n",
    "    print(\"游戏开始啦\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit = int(input(\"guess_digit:\")) # 玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes,you got it.\")\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小了想想。。\")\n",
    "            else:\n",
    "                print(\"往大了猜。。。\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对，你个笨蛋！\")\n",
    "            print(\"正确答案是： %s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间，不要耍赖！！！\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5b1a5c7",
   "metadata": {},
   "source": [
    "# 购物车"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d0231ca",
   "metadata": {},
   "source": [
    "* 购物车程序项目：\n",
    "> 1.运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。        \n",
    "> 2.让用户输入商品编号进行商品的购买。         \n",
    "> 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。                  \n",
    "> 4.用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。              \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1cb9797a",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bc3c280f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入余额56\n",
      "-----蜜雪冰城列表-----\n",
      "蜜桃四季春 6元\n",
      "冰鲜柠檬水 4元\n",
      "草莓啵啵奶盖 10元\n",
      "杨枝甘露 12元\n",
      "请输入商品编号6\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'AliPay' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [12]\u001b[0m, in \u001b[0;36m<cell line: 24>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     20\u001b[0m user_choice \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m请输入商品编号\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m     22\u001b[0m \u001b[38;5;66;03m# 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\u001b[39;00m\n\u001b[1;32m---> 24\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mAliPay\u001b[49m \u001b[38;5;241m>\u001b[39m good_list[user_choice][\u001b[38;5;241m1\u001b[39m]:\n\u001b[0;32m     25\u001b[0m     \u001b[38;5;66;03m# 余额足够\u001b[39;00m\n\u001b[0;32m     26\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m购买成功，等待制作\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m     28\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m     29\u001b[0m     \u001b[38;5;66;03m# 余额不够\u001b[39;00m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'AliPay' is not defined"
     ]
    }
   ],
   "source": [
    "# 1.运行程序后，让用户驶入支付宝余额，然后打印我们的商品列表给用户\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"冰鲜柠檬水\",4],\n",
    "    [\"草莓啵啵奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "# 数据存放，列表的增加（append）\n",
    "shopping_list = []\n",
    "\n",
    "\n",
    "Alipay = int(input(\"请输入余额\"))\n",
    "\n",
    "while True：\n",
    "print(\"-----蜜雪冰城列表-----\")\n",
    "for i in range(4):\n",
    "    print(good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "# 第一种，每个都print，繁琐版\n",
    "# print(good_list[0][0],good_list[0][1])\n",
    "# print(good_list[1][0],good_list[1][1])\n",
    "# print(good_list[2][0],good_list[2][1])\n",
    "# print(good_list[3][0],good_list[3][1])\n",
    "\n",
    "# 2.让用户输入商品编号,进行商品的购买\n",
    "user_choice = int(input(\"请输入商品编号\"))\n",
    "\n",
    "# 3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    "# 3.1 用户输入商品序号\n",
    "if\n",
    "if AliPay > good_list[user_choice][1]:\n",
    "    # 余额足够\n",
    "    AliPay = AliPay - good_list[user_choice][1] # 更新用户余额\n",
    "    shopping_list.append(good_list[user_choice])\n",
    "    print(\"购买成功，请等待制作。。。。，您的余额还有：%s元\"%(AliPay))\n",
    "    \n",
    "else:\n",
    "    # 余额不够\n",
    "    print(\"你连\"+str(good_list[user_choice][1])+\"元都没有，还有脸喝蜜雪冰城！！哼！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03858e30",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
